//
//  DefineView.m
//  换换圈
//
//  Created by 谭小贱 on 14-12-18.
//  Copyright (c) 2014年 艾柯斯. All rights reserved.
//

#import "DefineView.h"
#define KScreen



@interface DefineView() {
    UIView* _backgroundView;
}

@end

@implementation DefineView


-(NSDate*)chooseDate
{
    return _datePicker.date;
}


-(instancetype)initWithFrame:(CGRect)frame {
    if(self = [super initWithFrame:frame]) {
        
        self.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
        _backgroundView = [[UIView alloc] init];
        [self addSubview:_backgroundView];
        
        _bgView=[[UIView alloc]init];
        _bgView.backgroundColor=[UIColor whiteColor];
        [_backgroundView addSubview:_bgView];
        
        _datePicker=[[UIDatePicker alloc]init];
        _datePicker.datePickerMode=UIDatePickerModeDate;
        [_bgView addSubview:_datePicker];
        
        _content=[[UILabel alloc]init];
         _content.textAlignment=NSTextAlignmentCenter;
         _content.text=@"请选择破蛋年月日";
         _content.backgroundColor=[UIColor whiteColor];
         _content.textColor=[UIColor grayColor];
        [_backgroundView addSubview:_content];
        
        _cancelButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        _cancelButton.backgroundColor=[UIColor whiteColor];
        [_cancelButton setTintColor:[UIColor blueColor]];
        [_cancelButton addTarget:self action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchUpInside];
        [_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
  
        [_backgroundView addSubview:_cancelButton];
        
        
        _comfirmButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        _comfirmButton.backgroundColor=[UIColor whiteColor];
        [_comfirmButton setTitle:@"确认" forState:UIControlStateNormal];
        [_comfirmButton setTintColor:[UIColor redColor]];
        [_backgroundView addSubview:_comfirmButton];
   
    }
    return self;
}

-(void)didMoveToWindow {

    _backgroundView.frame = CGRectMake(0, self.frame.size.height, self.frame.size.width, self.frame.size.height);
    [_cancelButton setFrame:CGRectMake(7, _backgroundView.frame.size.height-7-43, _backgroundView.frame.size.width-2*7, 43)];
    [_comfirmButton setFrame:CGRectMake(7, _cancelButton.frame.origin.y-7-43, _backgroundView.frame.size.width-2*7, 43)];
    [_bgView setFrame:CGRectMake(7, _comfirmButton.frame.origin.y-30-216, _backgroundView.frame.size.width-14, 216)];
    [_datePicker setFrame:CGRectMake(0, 0, _bgView.frame.size.width, _bgView.frame.size.height)];
    [_content setFrame:CGRectMake(_bgView.frame.origin.x, _bgView.frame.origin.y-7-43, _bgView.frame.size.width, 43)];
    
    [UIView animateWithDuration:0.5 animations:^{
        CGRect frame  = _backgroundView.frame;
        frame.origin.y = 0;
        _backgroundView.frame = frame;
    }];
}

-(void)showInView:(UIView *)view {

    
    self.frame = view.bounds;
    self.autoresizingMask = kAutoresizingMaskAll;
    [view addSubview:self];
    
  
}
@end
